package cn.ffcs.uec.view.dao.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.common.util.PermissionUtil;
import cn.ffcs.uec.view.dao.LogDownDao;
import cn.ffcs.uec.view.model.LogDown;
import cn.ffcs.uec.view.model.UecStaffAll;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;
@Repository("logDownDao")
@Transactional
public class LogDownDaoImpl extends BaseDaoImpl implements LogDownDao {

	@Override
	public LogDown findLogDownByLogDown(LogDown logDown) {
		StringBuilder sb = new StringBuilder(
				" SELECT * FROM LOG_DOWN T  WHERE 1=1 ");
		List<Object> params = new ArrayList<Object>();
		List<LogDown> list =null;
		if (logDown != null) {
			   if(!StrUtil.isNullOrEmpty(logDown.getCode())) {
				sb.append(" AND T.CODE = ? ");
				params.add(logDown.getCode().toUpperCase());
			   }
			   if(!StrUtil.isNullOrEmpty(logDown.getPkPsndoc())) {
				   sb.append(" AND T.PK_PSNDOC = ? ");
				   params.add(logDown.getPkPsndoc());
			   }
			   if(!StrUtil.isNullOrEmpty(logDown.getName())) {
				sb.append(" AND T.NAME = ? ");
				params.add(logDown.getName());
			   }  
			   if(!StrUtil.isNullOrEmpty(logDown.getSignno())) {
				   sb.append(" AND T.SIGNNO = ? ");
				   params.add(logDown.getSignno());
			   }else {
				   sb.append(" AND T.SIGNNO is null ");
			   }  
			   sb.append(" order by T.CREATETIME desc");
			list = this.jdbcFindList(sb.toString(),params, LogDown.class);
			if (list.size() > 0 && list != null) {
				return list.get(0);
			}
		}
		return null;
	}

	@Override
	public PageInfo queryPageInfoByUecStaffAll(UecStaffAll uecStaffAll,String type,int current, int pageSize) {
		if (null != uecStaffAll) {
			String orgName = PermissionUtil.getManagerOrg();
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM LOG_DOWN T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.openswitch = 'Y' ");

			if (!StrUtil.isNullOrEmpty(uecStaffAll.getPkpsndoc())) {
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecStaffAll.getPkpsndoc());
			}
			if (!StrUtil.isNullOrEmpty(uecStaffAll.getName())) {
				sb.append(" AND T.NAME = ? ");
				params.add(uecStaffAll.getName());
			}
			if (!StrUtil.isNullOrEmpty(uecStaffAll.getCode())) {
				sb.append(" AND T.CODE = ? ");
				params.add(uecStaffAll.getCode());
			}
			if(!StrUtil.isNullOrEmpty(type)) {
				sb.append(" AND T.TALENTNAME = ? ");
				params.add(type);
			}
			if(!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
				sb.append(" AND T.WORKORG like ? ");
				params.add("%"+orgName+"%");
			}
			if(!StrUtil.isNullOrEmpty(type)) {
				   sb.append(" AND T.SIGNNO = ? ");
				   params.add(type);
			   }else {
				   sb.append(" AND T.SIGNNO is null ");
			   }  
			sb.append(" order by T.downtime desc ");
			 //System.out.println("sb----------"+sb.toString());
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, LogDown.class);
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> getLogDownList(UecStaffAll uecStaffAll,String type) {
		String orgName = PermissionUtil.getManagerOrg();
		StringBuilder sb = new StringBuilder(
				" SELECT "
				+ " T.STAFFCATOGERY 人员类别, T.WORKFORG 上级单位, T.WORKORG 报送单位,T.TALENTGRADE 人才等级,T.TALENTTYPE 申报类型,"
				+ " T.TALENTNAME 申报专业, T.CHILDTALENTNAME 子专业,T.CODE 人员编码, T.NAME 人员姓名, T.SEX 性别, T.BIRTHDATE 出生年月, T.PARTYNAME 政治面貌,"
				+ " T.WORKORGDEPT 工作单位及部门, T.WORKPOSTGRADE 岗位及岗级, to_char(T.begindatetanlent,'yyyy-mm') 从事此申报专业起始时间, to_char(T.begindatechild,'yyyy-mm') 从事本子专业起始时间,"
				+ " T.JOINWORKDATE 参加工作日期, T.ENTERUNITTIME 进入电信时间, T.uecnationdutylist 专业资格证书及获得年月,"
				+ " T.issupervisor 是否曾聘组监, T.uectalentteamlist BCD级人才聘期及考核结果, T.titleinfo 专业技术职称, T.mobile 联系电话, T.EMAIL 电子邮箱,"
				+ " '产品类:'||T.Talentchanpin||'/行业类:'||T.Talenthangye  人才标签, T.UECWORKLIST 工作简历,T.ALLSTUDY 全日制教育, T.ZAISTUDY 在职教育,"
				+ "  T.ASS2016  年度2016考核, T.ASS2017  年度2017考核, T.ASS2018  年度2018考核, T.UECENCLIST 近三年获奖情况, T.UECINNOVATIONLIST 近三年创新成果,"
				+ " T.UECARTICLELIST 近三年论文专著发表情况, T.UECIMPORTANTWORKLIST 近三年参加本单位工作, T.UECIMPORTANTWORKJLIST 近三年参加集团工作"
				+ " FROM LOG_DOWN T WHERE 1 = 1 ");
		//StringBuilder sb = new StringBuilder(" SELECT T.STAFFCATOGERY 人员类别, T.CODE 编码,T.NAME 姓名 FROM　LOG_DOWN T");
		List<Object> params = new ArrayList<Object>();
		sb.append(" AND T.openswitch = 'Y' ");
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getName())) {
			sb.append(" AND T.NAME = ? ");
			params.add(uecStaffAll.getName());
		}
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getCode())) {
			sb.append(" AND T.CODE = ? ");
			params.add(uecStaffAll.getCode());
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			sb.append(" AND T.TALENTNAME = ? ");
			params.add(type);
		}
		if(!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.WORKORG like ? ");
			params.add("%"+orgName+"%");
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			   sb.append(" AND T.SIGNNO = ? ");
			   params.add(type);
		   }else {
			   sb.append(" AND T.SIGNNO is null ");
		   }  
		sb.append(" order by T.WORKORG desc ");
		return this.getJdbcTemplate().queryForList(sb.toString(), params.toArray());
	}
	@Override
	public List<Map<String, Object>> getLogDownListByWB(UecStaffAll uecStaffAll,String type) {
		String orgName = PermissionUtil.getManagerOrg();
		StringBuilder sb = new StringBuilder(
				" SELECT "
				+ " T.STAFFCATOGERY 人员类别, T.WORKFORG 上级单位, T.WORKORG 报送单位,T.TALENTGRADE 人才等级,T.TALENTTYPE 申报类型,"
				+ " T.TALENTNAME 申报专业, T.CHILDTALENTNAME 子专业,T.CODE 人员编码, T.NAME 人员姓名, T.SEX 性别, T.BIRTHDATE 出生年月, T.PARTYNAME 政治面貌,"
				+ " T.WORKORGDEPT 工作单位及部门, T.WORKPOSTGRADE 岗位及岗级, to_char(T.begindatetanlent,'yyyy-mm') 从事此申报专业起始时间, to_char(T.begindatechild,'yyyy-mm') 从事本子专业起始时间,"
				+ " T.JOINWORKDATE 参加工作日期, T.ENTERUNITTIME 进入电信时间, T.uecnationdutylist 专业资格证书及获得年月,"
				+ " T.issupervisor 是否曾聘组监, T.uectalentteamlist BCD级人才聘期及考核结果, T.titleinfo 专业技术职称, T.mobile 联系电话, T.EMAIL 电子邮箱,"
				+ " '产品类:'||T.Talentchanpin||'/行业类:'||T.Talenthangye  人才标签, T.UECWORKLIST 工作简历,T.ALLSTUDY 全日制教育, T.ZAISTUDY 在职教育,"
				+ "  T.ASS2016  年度2016考核, T.ASS2017  年度2017考核, T.ASS2018  年度2018考核, T.UECENCLIST 近三年获奖情况 "
				+ " FROM LOG_DOWN T WHERE 1 = 1 ");
		//StringBuilder sb = new StringBuilder(" SELECT T.STAFFCATOGERY 人员类别, T.CODE 编码,T.NAME 姓名 FROM　LOG_DOWN T");
		List<Object> params = new ArrayList<Object>();
		sb.append(" AND T.openswitch = 'Y' ");
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getName())) {
			sb.append(" AND T.NAME = ? ");
			params.add(uecStaffAll.getName());
		}
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getCode())) {
			sb.append(" AND T.CODE = ? ");
			params.add(uecStaffAll.getCode());
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			sb.append(" AND T.TALENTNAME = ? ");
			params.add(type);
		}
		if(!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.WORKORG like ? ");
			params.add("%"+orgName+"%");
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			   sb.append(" AND T.SIGNNO = ? ");
			   params.add(type);
		   }else {
			   sb.append(" AND T.SIGNNO is null ");
		   }  
		sb.append(" order by T.WORKORG desc ");
		return this.getJdbcTemplate().queryForList(sb.toString(), params.toArray());
	}

	@Override
	public List<LogDown> getLogDownListAll(UecStaffAll uecStaffAll, String type) {
		String orgName = PermissionUtil.getManagerOrg();
		StringBuilder sb = new StringBuilder(
				" SELECT * FROM LOG_DOWN T WHERE 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		sb.append(" AND T.openswitch = 'Y' ");

		if (!StrUtil.isNullOrEmpty(uecStaffAll.getPkpsndoc())) {
			sb.append(" AND T.PK_PSNDOC = ? ");
			params.add(uecStaffAll.getPkpsndoc());
		}
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getName())) {
			sb.append(" AND T.NAME = ? ");
			params.add(uecStaffAll.getName());
		}
		if (!StrUtil.isNullOrEmpty(uecStaffAll.getCode())) {
			sb.append(" AND T.CODE = ? ");
			params.add(uecStaffAll.getCode());
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			sb.append(" AND T.TALENTNAME = ? ");
			params.add(type);
		}
		if(!"区本部".equals(orgName) && !StrUtil.isNullOrEmpty(orgName)) {
			sb.append(" AND T.WORKORG like ? ");
			params.add("%"+orgName+"%");
		}
		if(!StrUtil.isNullOrEmpty(type)) {
			   sb.append(" AND T.SIGNNO = ? ");
			   params.add(type);
		   }else {
			   sb.append(" AND T.SIGNNO is null ");
		   } 
		sb.append(" order by T.downtime desc ");
		return this.jdbcFindList(sb.toString(), params,LogDown.class);
	}

	
	
}
